package p2;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

import javax.swing.JFileChooser;

public class HospitalMatrixLoader {

	public int flow[][];
	public int distance[][];
	private File file;
	
	
	public HospitalMatrixLoader(){
		JFileChooser jfc = new JFileChooser(System.getProperty("user.dir"));
		int returnVal = jfc.showOpenDialog(null);
		
		if (returnVal == JFileChooser.APPROVE_OPTION) {
	            file = jfc.getSelectedFile();
	            readFromFile();
		}
	}

	public HospitalMatrixLoader(String pathFile){
		
		file = new File(pathFile);
	    readFromFile();
		
	}

	private void readFromFile() {
		try {
			FileInputStream fis = new FileInputStream(file);
			BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
			
			String line = reader.readLine();
			String values[];
			
			int nLines = Integer.parseInt(line);
			
			flow = new int[nLines][nLines];
			distance = new int[nLines][nLines];
			
			reader.readLine();
			
			for (int i=0;i<nLines;i++){
				line = reader.readLine();
				values = line.split(" ");
				for (int j=0;j<nLines;j++){
					distance[i][j] = Integer.parseInt(values[j]);
				}
			}
			
			reader.readLine();
			
			for (int i=0;i<nLines;i++){
				line = reader.readLine();
				values = line.split(" ");
				for (int j=0;j<nLines;j++){
					flow[i][j] = Integer.parseInt(values[j]);
				}
			}
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
        


	}
}
